package czx.wt.util;

import czx.wt.web.exception.MessageUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * @Description: permission 工具类
 * @Author: ChenZhiXiang
 * @CreateDate: 2019/2/13 0013 9:30
 * @Version: 1.0
 */
public class PermissionUtils {

    /**
     * 权限错误消息提醒
     *
     * @param permissionsStr 错误信息
     * @return
     */
    public static String getMsg(String permissionsStr)
    {
        String permission = org.apache.commons.lang3.StringUtils.substringBetween(permissionsStr, "[", "]");
        String msg = MessageUtils.message("no.view.permission", permission);
        if (org.apache.commons.lang3.StringUtils.endsWithIgnoreCase(permission, PermissionConstants.ADD_PERMISSION))
        {
            msg = MessageUtils.message("no.create.permission", permission);
        }
        else if (org.apache.commons.lang3.StringUtils.endsWithIgnoreCase(permission, PermissionConstants.EDIT_PERMISSION))
        {
            msg = MessageUtils.message("no.update.permission", permission);
        }
        else if (org.apache.commons.lang3.StringUtils.endsWithIgnoreCase(permission, PermissionConstants.REMOVE_PERMISSION))
        {
            msg = MessageUtils.message("no.delete.permission", permission);
        }
        else if (org.apache.commons.lang3.StringUtils.endsWithIgnoreCase(permission, PermissionConstants.EXPORT_PERMISSION))
        {
            msg = MessageUtils.message("no.export.permission", permission);
        }
        else if (StringUtils.endsWithAny(permission,
                new String[] { PermissionConstants.VIEW_PERMISSION, PermissionConstants.LIST_PERMISSION }))
        {
            msg = MessageUtils.message("no.view.permission", permission);
        }
        return msg;
    }
}
